"""
@author: wangxutao
@project: ZetCore
@file: pagination.py
@time: 2019/9/6 16:26
@desc: 自定义的restframework的分页器
"""
from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.status import HTTP_200_OK


class ZetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'pageSize'
    max_page_size = 50000

    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('code', HTTP_200_OK),
            ('message', 'success'),
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('data', data)
        ]))


